library TeamColorCommand initializer init requires LegacySystem

	globals
		private boolean tcEnabled = false
	endglobals
	
	private function SitrepEnabled takes nothing returns boolean
		return tcEnabled
	endfunction
	
	function EnableTC takes nothing returns nothing
		set tcEnabled = true
	endfunction
	
	private function TeamColorCommand takes nothing returns nothing
		local player p = GetTriggerPlayer()
		local integer i
		local integer i2
		local integer color = S2I(SubString(GetEventPlayerChatString(),4,StringLength(GetEventPlayerChatString())))
		call DisableTrigger(GetTriggeringTrigger())
		if p==Player(0) then
			set i = 0
		else
			set i = 5
		endif
		set i2 = i+4
		loop
			exitwhen i>i2
			if i==9 then
				set i=10
			endif
			call SetPlayerColor( Player(i), ConvertPlayerColor(color) )
			set i = i + 1
		endloop
		call PolledWait(1.5)
		call EnableTrigger(GetTriggeringTrigger())
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger()
		call TriggerRegisterPlayerChatEvent(t,Player(0),"-tc",false)
		call TriggerRegisterPlayerChatEvent(t,Player(5),"-tc",false)
		call TriggerAddCondition(t, Condition(function SitrepEnabled))
		call TriggerAddAction(t,function TeamColorCommand)
	endfunction
	
endlibrary